CC =	g++
CFLAGS = -MMD -c -std=c++0x -DGLEW_STATIC
#-Isrc/
ifeq ($(DEBUG),n)
CFLAGS	+= -Ofast -fdata-sections -ffunction-sections
else
CFLAGS	+= -D__DEBUG__ -g3 -Og
endif
#LDFLAGS =  -lglew32s -lopengl32 -lglu32 -lmingw32 -l:libSDL2main.a -l:libSDL2.a -lwinmm -lole32 -loleaut32 -lgdi32 -limm32 -luuid -lm
LDFLAGS =  -lglew32s -lopengl32 -lglu32 -lmingw32 -l:libSDL2main.a -l:libSDL2.a -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion
#LDFLAGS =	-lglew32s -lopengl32 -lgdi32 -lglu32 -lSDL2
#LDFLAGS = -lX11 -l:libSDL2.a -ldl -lpthread -lGL -lGLEW -lc
ifeq ($(DEBUG),n)
LDFLAGS += -Wl,--gc-sections  -Wl,--strip-all
endif
SHARED_SOURCES = leak.cpp RayTracing.cpp MyWindow.cpp PolyPlane.cpp Camera.cpp GLRenderer.cpp Matrices_old.cpp BSP.cpp GLMesh.cpp Entities.cpp
#SHARED_SOURCES = leak.cpp all.cpp
SHARED_SOURCES1 = leak.cpp RayTracing.cpp MyWindow.cpp PolyPlane.cpp Camera.cpp GLRenderer.cpp Matrices_old.cpp GLMesh.cpp
EDITOR_SOURCES = editor/ChooseTextureWindow.cpp editor/TextureWindow.cpp editor/EditorWindow.cpp editor/EditorCommands.cpp editor/Editor.cpp editor/globals.cpp editor/main.cpp $(SHARED_SOURCES)
#EDITOR_SOURCES = editor/all.cpp all1.cpp all2.cpp all3.cpp
BUILDER_SOURCES = builder/Builder.cpp builder/MainWindow.cpp builder/globals.cpp builder/main.cpp $(SHARED_SOURCES)
MODEL_SOURCES = model/tri_stripper.cpp model/ViewModelWindow.cpp model/globals.cpp model/main.cpp $(SHARED_SOURCES1)
DIR = Debug
ifeq ($(DEBUG),n)
DIR = Release
endif

EDITOR_OBJECTS =	$(EDITOR_SOURCES:%.cpp=$(DIR)/%.o)
EDITOR_SOURCES1 =	$(EDITOR_SOURCES:%.cpp=src/%.cpp)

BUILDER_OBJECTS =	$(BUILDER_SOURCES:%.cpp=$(DIR)/%.o)
BUILDER_SOURCES1 = $(BUILDER_SOURCES:%.cpp=src/%.cpp)

MODEL_OBJECTS =	$(MODEL_SOURCES:%.cpp=$(DIR)/%.o)
MODEL_SOURCES1 = $(MODEL_SOURCES:%.cpp=src/%.cpp)

EDITOR_EXECUTABLE = editor
BUILDER_EXECUTABLE = builder
MODEL_EXECUTABLE = model

EDITOR_DEPS = $(EDITOR_SOURCES:%.cpp=$(DIR)/%.d)
BUILDER_DEPS = $(BUILDER_SOURCES:%.cpp=$(DIR)/%.d)
MODEL_DEPS = $(MODEL_SOURCES:%.cpp=$(DIR)/%.d)

-include $(DIR)/*.d
-include $(DIR)/editor/*.d
-include $(DIR)/model/*.d
-include $(DIR)/buider/*.d

editor:	$(EDITOR_SOURCES1) $(EDITOR_EXECUTABLE)
	
$(EDITOR_EXECUTABLE): $(EDITOR_OBJECTS) 
	$(CC) -o $@ $(EDITOR_OBJECTS) $(LDFLAGS)

$(DIR)/%.o: src/%.cpp src/%.h src/%.d
	$(CC) $(CFLAGS) $< -o $@ 

$(DIR)/editor/%.o: src/editor/%.cpp src/editor/%.h src/%.h src/editor/%.d
	$(CC) $(CFLAGS) $< -o $@

editor_clean:
	del $(subst /,\,$(EDITOR_OBJECTS)) $(EDITOR_EXECUTABLE) $(subst /,\,$(EDITOR_DEPS))
	
	
builder:	$(BUILDER_SOURCES1) $(BUILDER_EXECUTABLE)

$(BUILDER_EXECUTABLE): $(BUILDER_OBJECTS) 
	$(CC) -o $@ $(BUILDER_OBJECTS) $(LDFLAGS)


$(DIR)/builder/%.o: src/builder/%.cpp src/builder/%.h src/%.h src/builder/%.d
	$(CC) $(CFLAGS) $< -o $@

$(DIR)/%.o: src/%.cpp
	$(CC) $(CFLAGS) $< -o $@

	
builder_clean:
	del $(subst /,\,$(BUILDER_OBJECTS)) $(BUILDER_EXECUTABLE) $(subst /,\,$(BUILDER_DEPS))


model:	$(MODEL_SOURCES1) $(MODEL_EXECUTABLE)

$(MODEL_EXECUTABLE): $(MODEL_OBJECTS) 
	$(CC) -o $@ $(MODEL_OBJECTS) $(LDFLAGS)


$(DIR)/model/%.o: src/model/%.cpp src/model/%.h src/%.h src/model/%.d
	$(CC) $(CFLAGS) $< -o $@

$(DIR)/%.o: src/%.cpp
	$(CC) $(CFLAGS) $< -o $@

	
model_clean:
	del $(subst /,\,$(MODEL_OBJECTS)) $(MODEL_EXECUTABLE) $(subst /,\,$(MODEL_DEPS))

